import plotly.graph_objects as go
import pandas as pd

class BasicDraws(object):
    '''
    总结一些绘制曲线图的功能：优先使用plotly
    '''
    def __init__(self, df, save=False):
        self.df = df
        self.save = save

    def curve(self, x, y_list, title=None, savepath=None):
        '''
        基础的绘制多个曲线的功能：
        :param x: 作为横轴的列名 string
        :param y_list: 作为纵轴的列名的列表 list of string
        :param title: 图的名称, string
        :param savepath: 存储的路径, 存储文件以.html为后缀 string
        :return: None
        '''
        fig = go.Figure()
        x = df[x].values
        for columns_name in y_list:
            y = df[columns_name].values
            fig.add_trace(go.Scatter(x=x, y=y,
                                     mode='lines+markers',
                                     name=columns_name))
        # 添加标题（默认居中）
        fig.update_layout(title=title)
        # fig.show()
        if self.save is True:
            fig.write_html(savepath)

if __name__ == '__main__':
    df = pd.read_excel(r'D:\work_files\projcet\generation_hour\phour_easy_report\不同气象数据集的对比\省会城市年辐照度对比-不同数据资源青藏所vsMeteonorm.xlsx',
                       sheet_name='Sheet3')
    df['address']=df['name']+df['city']
    df = df.rename(columns={'qz_GHI':'青藏所_GHI','pv_GHI': 'pvsyst_GHI', 'GHI_solargis': 'solargis_GHI', 'GHI_NASA': 'NASA_GHI'})
    draw = BasicDraws(df, True)
    draw.curve('address', ['青藏所_GHI','pvsyst_GHI','solargis_GHI','NASA_GHI'],'不同气象资源的GHI对比图', 'D:\work_files\projcet\generation_hour\phour_easy_report\不同气象数据集的对比\对比图.html')

